/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package optimization;

import queryTree.TableCouple;

/**
 *
 * @author yulian
 */
public class Condition {
    public Condition(){
        this.operator=operator_type.NULL;
    }
    public Field lhs=new Field();
    public String lhs_s = new String();
    public Field rhs=new Field();
    public String rhs_s = new String();
    public operator_type operator;
    
    /**
     * for comparision
     * @author Van
     */
	
	public int hashCode() {
		return lhs.hashCode() + rhs.hashCode() + operator.hashCode();
	}
	 /**
	  * for comparision
	  * @author Van
	  */
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o instanceof Condition) {
			Condition other = (Condition) o;			
			if(lhs.equals(other.lhs) && rhs.equals(other.rhs) && operator == other.operator) {
				return true;
			} else if (operator == operator_type.LARGER && other.operator == operator_type.SMALLER
				|| operator == operator_type.SMALLER && other.operator == operator_type.LARGER
				|| operator == operator_type.LARGER_OR_EQUAL && other.operator == operator_type.SMALLER_OR_EQUAL
				|| operator == operator_type.SMALLER_OR_EQUAL && other.operator == operator_type.LARGER_OR_EQUAL){
				
				return (lhs.equals(other.rhs) && rhs.equals(other.lhs));
			}
				   
		}
		return false;
	}
}
